home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: function similar to strtok() needed
- Date: 23 Feb 96 14:34:58 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.825086098@rscernix>
- References: <4gipop$igp@savvy2.savvy.com>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <4gipop$igp@savvy2.savvy.com> phil@savvy1.savvy.com (Phil Schwartz) writes:
-
- >I want to be able to parse a line, say "this is a test&it better work!ok"
- >and grab the tokens which I will consider to be anything except the
- >space (" "), ampersand ("&") and exclamation point ("!"). Strtok() seems to
- >be a good starting point:
- ...
- >However, what if I want to know which of the characters (in tokens) was
- >the separator between two tokens (tok)? For example, when tok is "test"
- >the separator was a space and when tok is "it", the separator is the
- >ampersand.
- >
- >I'm sure I could add write a hocked up routine to do this, but I figure
- >there must be some elegant way of finding out this information.
-
- Your guess is right and the name of the function is sscanf. Read its
- description carefully. If the (maximum) number of tokens is not known
- at compile time, you'll have to combine sscanf and strchr to get one
- token at a time from the string.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-